package com.study.leetcode;

import java.util.Arrays;

/**
 * @description: TowNumberSum 两数之和
 * @date: 2020/11/19 19:01
 * @author: hcm
 * @version: 1.0
 */
public class TowNumberSum {

    public static void main(String[] args) {
    int[] arr ={0,4,3,0};
        int[] ints = twoSum(arr, 0);
        System.out.println(Arrays.toString(ints));
    }

    /**
     *    两数之和,找出和为目标值的两个整数
     */
    public static int[] twoSum(int[] nums, int target) {

        int len = nums.length;

        int[] res = new int[2];

        if(nums==null){
            return new int[0];
        }

        //遍历
        for (int i = 0; i < len; i++) {

            //边界
            if(i ==len-1){
                break;
            }
            for (int j = i+1; j < len; j++) {

                //两数之和成立条件
                if(nums[i]+nums[j] ==target){
                    res[0] = i;
                    res[1] = j;
                }
            }
        }
        return res;
    }
}
